#include "MlpAgent.h"

namespace fullsail_ai {

	void MlpAgent::initialize(int (*numberGenerator)(), std::size_t inputCount,
	                          std::size_t hiddenNeuronCount, std::size_t actionCount)
	{
		// TODO: 1
		// Forward the arguments to the corresponding /network/ method
		// and resize the /currentOutputs/ container.
		network.initialize(numberGenerator,inputCount,hiddenNeuronCount,actionCount);
		currentOutputs.resize(actionCount);
		currentActionIndex = actionCount-1;
	}

	std::size_t MlpAgent::computeIndexOfMaxOutput(std::vector<double> const& outputs)
	{
		// TODO: 9a
		// Find the largest value in the /outputs/ container and return its index.
		unsigned largest = 0;
		double largestNum = outputs.front();
		for(unsigned i = 1; i < outputs.size();i++)
		{
			if(outputs[i] > largestNum)
			{
				largest = i;
				largestNum = outputs[i];
			}
		}
		return largest;
	}

	void MlpAgent::update(std::vector<double> const& inputs)
	{
		// TODO: 9b
		// Update the agent's action and outputs using the given inputs.
		network.generateOutputs(inputs,currentOutputs);
		currentActionIndex = computeIndexOfMaxOutput(inputs);
	}

	void MlpAgent::train(std::vector<std::vector<double> > const& trainingSetInputs,
	                     std::vector<std::vector<double> > const& expectedOutputs,
	                     double learningFactor)
	{
		// TODO: 14
		// Forward the arguments to the /network/ method with matching parameters.
	}
}  // namespace fullsail_ai

